/*
* Poppy Game Engine - https://pgetemplate.googlecode.com/svn/
* -----------------------------------------------------------------------
* Licensed under the BSD license, see LICENSE in PSPSDK root for details.
*
* Copyright (c) 2008 Poppy
*/

#pragma once

#include "RendererExportSymbol.h"
#include "SystemDefines.h"
#include "RendererDefines.h"

namespace PGERenderer
{

	enum EClearFlag
	{
		CLEAR_COLOR = 0,
		CLEAR_STENCIL,
		CLEAR_COLOR_STENCIL,
		CLEAR_DEPTH,
		CLEAR_AREA,
		CLEAR_ENABLE
	};
	
	typedef struct SCopyData
	{
		int psm;
		int sx;
		int sy;
		int width;
		int height;
		int srcw;
		void* src;
		int dx;
		int dy;
		int destw;
		void* dest;
	} COPYDATA;

	class CGraphicSystemData;

	class PGERENDERER_API CPSPDriver
	{

	public:
		
		void InitGraphicSystem();
		
		void TermGraphicSystem();
		
		bool BeginScene();
		
		void EndScene();
		
		void Present();
		
		void* GetMemory(int size);
		
		void SendCommandi(int cmd, int argument);
				
		void SendCommandf(int cmd, float argument);
				
		void CommandStall();
		
		
		void SetVertexType(unsigned int vt, unsigned int vtsize);

		void DrawVertex(PGEPRIMITIVE_TYPE prim, unsigned int count, LPVERTEX_BUFFER vertices);

		void DrawIndex(PGEPRIMITIVE_TYPE prim, unsigned int count, unsigned int vertexs, LPVERTEX_BUFFER vertices, LPINDEX_BUFFER indices);
		
		void CopyImage(const COPYDATA* data);
		
		void CopyImageToBuffer(COPYDATA* data);
		
		void* GetBuffer();
		
		
		void DepthRange(int near, int far);
				
		void FrontFace(int order);
				
		void ShadeModel(int mode);
				
		void Clear();

		void ClearState(EClearFlag flag, unsigned int value);
		
		void DrawRegion(int x, int y, int width, int height);
		
		void SetDither(const int* matrix);
		
		void PatchDivide(unsigned int ulevel, unsigned int vlevel);
		
		void ColorMaterial(int  components);
		
		void Specular(float power);
		
		void TexScale(float u, float v);
		
		void Offset(unsigned int x, unsigned int y);
		
		void Viewport(int cx, int cy, int width, int height);
		
		void Scissor(int x, int y, int w, int h);
		
		
		static void CallbackFin(int id, void* arg);
		
		static void CallbackSig(int id, void* arg);
		
		static CPSPDriver* GetInstance();

		static void Release();

	protected:

		void Start();
		
		void Setup();
		
		void SetBuffers();

		static CPSPDriver* m_pInstance;
		CGraphicSystemData* m_pData;
		bool m_bIsInited;

		CPSPDriver();

		virtual ~CPSPDriver();

	};

}

